<template>
    <!-- 遮罩层 -->
    <view class="dropdown-overlay" :class="{ visible: visible }" @tap="close"></view>

    <!-- 下拉菜单 -->
    <view class="dropdown-menu" :class="{ visible }" :style="position" @tap.stop>
        <slot></slot>
    </view>
</template>

<script setup lang="ts">
const props = defineProps({
    visible: {
        type: Boolean,
        default: false
    },
    position: {
        type: Object,
        default: () => ({})
    }
})

const emit = defineEmits(['update:visible'])

const close = () => {
    emit('update:visible', false)
}
</script>

<style scoped>
.dropdown-menu {
    position: fixed;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.dropdown-menu.visible {
    opacity: 1;
    visibility: visible;
}

.dropdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.dropdown-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 8px;
}

.dropdown-item:active {
    background-color: #f5f5f5;
}

.dropdown-icon {
    font-size: 20px;
    color: #333;
}

.dropdown-item.delete {
    color: #ff4d4f;
}

.dropdown-item.delete .dropdown-icon {
    color: #ff4d4f;
}
</style>